<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>爱乘车</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="keywords" content="关键词" />
<meta name="description" content="描述" />
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=1z2NSxXmzGR8xALcivxgsGMO9Fqz9ZU9"></script>
<script type="text/javascript">
	$(document).ready(function(){
		//创建查询对象
		var geolocation = new BMap.Geolocation();
		//调用getCurrentPosition函数
		geolocation.getCurrentPosition(function(position){
		//如果查询成功	
		if(this.getStatus() == BMAP_STATUS_SUCCESS){
			var x = position.point.lng;
			var y = position.point.lat;
	        document.getElementById("buslist").setAttribute("style","display:block");
	        document.getElementById("getlocation").setAttribute("style","display:none");

	        document.getElementById("pointx").value =position.point.lng; 
	        document.getElementById("pointy").value =position.point.lat;

	        setCookie("pointx",position.point.lng); 
	        setCookie("pointy",position.point.lat); 
	        //不用转换，直接用百度取到的数据，下面为gps转百度坐标的方法
			// var ggPoint = new BMap.Point(x, y);
			// translateCallback = function (convRst){
			// 	if(convRst.status === 0) {
			// 		var newPoint=convRst.points[0];
		 //            document.getElementById("gps").innerText=position.point.lng+","+position.point.lat;
		 //            document.getElementById("getlocation").innerText="已获取位置";
		 //            document.getElementById("baidu").innerText=newPoint.lng+","+newPoint.lat;
		 //            document.getElementById("buslist").setAttribute("style","display:block");
			//       }  
			//     }  
			//  setTimeout(function(){  
			//         var convertor = new BMap.Convertor();  
			//         var pointArr = [];  
			//         pointArr.push(ggPoint);  
			//         convertor.translate(pointArr, 1, 5, translateCallback);  
			//  }, 1000); 

			}
			else
			{
		    	alert('failed'+this.getStatus());
		    	
		    }
		},{enableHighAccuracy:true})
	})

	function checkNull()
	{	
		var num=0;
		$("input[type$='text']").each(function(){  
	          if($(this).val()=="")  
	          {
				  num++;
	          }  
	     });
		if(num>0)
	     {
			 $("#info1").addClass("show");  
			 return false;
	     }
	     else
	     {
			 return true;
	     }
	}

	function setCookie(name,value) 
	{ 
	    // var Days = 30; 
	    // var exp = new Date(); 
	    // exp.setTime(exp.getTime() + Days*24*60*60*1000); 
	    // document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); 
	    document.cookie = name + "="+ escape (value)+";path=/";//路径为全站起作用
	} 
</script>
</head>
<body>
<div id="allmap" style="display: none"></div>
<div class="tabwrap">
 <span><a href="/bus/search/getlocation.html">附近车站</a></span>
 <span class="tabon"><a href="#">搜索站点</a></span>
</div>
<form action="{:U('Bus/Search/searchHandle')}" method="post">
<input type="hidden" id="pointx" name="pointx"/>
<input type="hidden" id="pointy" name="pointy"/>




<div class="input-wrap">
	<input name="station_name" type="text" class="input-station" placeholder="请输入车次/站点名称" />
	<input type="submit" id="sub" value="查询" class="input-button" onclick="return checkNull()" />
</div>
<p class="errorinfo" id="info1">请输入车次/站点名称</p>

<span id="gps"></span>
<span id="getlocation" class="getlocation">正在获取地理位置信息…</span>
<span id="baidu"></span>


<div class="container">
	<div class="buslist" style="display:none" id="buslist">
	      <ul>
			  <foreach name="searchbus" item="lin">
				  <li>
				  	<a id="a{$key}" href="{:U('./Bus/Stationarticle/stationarticle3',array('lineid'=>$lin['lineid'],'sj'=>$lin['sj']))}">
					<div class="stops"><h2>{$lin.name}</h2></div>
					</a>
				  </li>
			  </foreach>	
        </ul>
	</div>
</div>

</form>
</body>
</html>
